/*
 * HubClientReader.java
 *
 * Created on 2 de Junho de 2006, 20:39
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */

package hubsniffer.db;

import libjdc.dc.client.HubClient;
import libjdc.dc.log.Log;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.LinkedList;

/**
 *
 * @author Daniel Botelho
 */
public class HubClientReader {
    
    private DataBaseManager db;
    private ResultSet rs;
    
    /** Creates a new instance of HubClientReader */
    public HubClientReader(DataBaseManager db) {
        this.db = db;
    }
    
    public LinkedList<HubClient> getHubClientList(){
        
        rs = null;
        try {
            rs = db.getSql_stm().executeQuery("select * from software");
        } catch (SQLException se) {
            Log.out.println("We got an exception while executing our query: that probably means our SQL is invalid");
            se.printStackTrace(Log.err);
            System.exit(1);
        }
                
        try {
            while (rs.next()) {   
                HubClient.addHubClient(new Integer(rs.getString("software_id")).intValue(),rs.getString("software_name"),rs.getString("software_homepage"),rs.getString("software_img"),rs.getString("parser_regex"));
            }
        } catch (SQLException se) {
            Log.out.println("We got an exception while getting a result:this shouldn't happen: we've done something really bad.");
            se.printStackTrace(Log.err);
            System.exit(1);
        }
        
        return HubClient.getAllClients();
    }
    
}
